<%--
  Created by IntelliJ IDEA.
  User: YWK
  Date: 2019/10/27
  Time: 12:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Tree</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
</head>
<body>

<div id="myTree"></div>
<button type="button" class="layui-btn layui-btn-sm" lay-demo="getChecked">获取选中节点数据</button>


<script>
    layui.use(['tree', 'util'], function(){
        var tree = layui.tree;
        var util = layui.util;
        var layer = layui.layer;


        //---------------树控件 start-------------
        var tree = tree.render({
            elem:'#myTree',
            showCheckbox:true,
            data:[],
            click:function (res) {
                console.log(res.data);
            }
        })
        $.ajax({
            url:'${pageContext.request.contextPath}/tree/show',
            dataType:'json',
            success:function (result) {
                tree.reload({
                    data:result
                });
            }
        });


        //按钮事件
        util.event('lay-demo', {
            getChecked: function(othis){
                var checkedData = tree.getChecked('#myTree'); //获取选中节点的数据

                layer.alert(JSON.stringify(checkedData), {shade:0});
                console.log(checkedData);
            }

        });
        /*var c = tree.getChecked('myTree');
        console.info(c[0]);
        console.info('----------');*/
        // var checkData = tree.getChecked('myTree');
//---------------树控件 end-------------

    });
</script>



</body>
</html>
